package com.ailiwu.www.ailiwu.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.ailiwu.www.ailiwu.R;
import com.ailiwu.www.ailiwu.base.BaseActivity;
import com.ailiwu.www.ailiwu.utils.SharedPrefUtils;

/**
 * Created by zzw on 2015/12/2.
 * <p/>
 * version 1.0
 */
public class IdentityActivity extends BaseActivity implements View.OnClickListener{
    private final static int BOY = 1;
    private final static int GIRL = 2;
    private final static int JUNIOR = 4;//初中生
    private final static int HIGH = 3;//高中生
    private final static int UNIVERSITY = 2;//大学生
    private final static int ROOKIE = 1;//职场新人
    private final static int WORKER = 0;//资深工作党

    private CardView cvSex,cvId;
    //身份选择条目
    private RelativeLayout mRlWorker,mRlRookie,mRlUniversity,mRlHigh,mRlJunior;
    //性别选择条目
    private LinearLayout mLlBoy,mLlGirl;
    //返回按钮
    private ImageView mivBack;
    //第一次选择
    private final static boolean ISFIRSTCHOOSE = true;

    @Override
    protected void loadXml() {
        setContentView(R.layout.activity_identity);

    }
    @Override
    protected void initView() {
        cvId = (CardView) findViewById(R.id.cv_id_id);
        cvSex = (CardView) findViewById(R.id.cv_id_sex);
        mRlJunior = (RelativeLayout) findViewById(R.id.rl_junior);
        mRlHigh = (RelativeLayout) findViewById(R.id.rl_high);
        mRlUniversity = (RelativeLayout) findViewById(R.id.rl_university);
        mRlRookie = (RelativeLayout) findViewById(R.id.rl_rookie);
        mRlWorker = (RelativeLayout) findViewById(R.id.rl_worker);
        mLlBoy = (LinearLayout) findViewById(R.id.ll_id_boy);
        mLlGirl = (LinearLayout) findViewById(R.id.ll_id_girl);
        mivBack = (ImageView) findViewById(R.id.iv_id_back);
    }
    @Override
    protected void initData() {
        //判断是否选择过
        boolean tmp = SharedPrefUtils.getBoolean(this,"ISFIRSTCHOOSE",false);
        if(tmp){
            startMainActivity();
        }
    }

    @Override
    protected void getIntentData(Bundle savedInstanceState) {

    }



    @Override
    protected void setListener() {

        mRlJunior.setOnClickListener(this);
        mRlHigh.setOnClickListener(this);
        mRlUniversity.setOnClickListener(this);
        mRlRookie.setOnClickListener(this);
        mRlWorker.setOnClickListener(this);
        mLlBoy.setOnClickListener(this);
        mLlGirl.setOnClickListener(this);
        mivBack.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.ll_id_boy:
                SharedPrefUtils.saveInt(this,"GENDER",BOY);
                cvSex.setVisibility(View.GONE);
                cvId.setVisibility(View.VISIBLE);
            break;
            case R.id.ll_id_girl:
                SharedPrefUtils.saveInt(this, "GENDER", GIRL);
                cvSex.setVisibility(View.GONE);
                cvId.setVisibility(View.VISIBLE);
            break;
            case R.id.rl_junior:
                SharedPrefUtils.saveInt(this, "GENERATION", JUNIOR);
                startMainActivity();
                break;
            case R.id.rl_high:
                SharedPrefUtils.saveInt(this, "GENERATION", HIGH);
                startMainActivity();
                break;
            case R.id.rl_university:
                SharedPrefUtils.saveInt(this, "GENERATION", UNIVERSITY);
                startMainActivity();
                break;
            case R.id.rl_rookie:
                SharedPrefUtils.saveInt(this, "GENERATION",ROOKIE);
                startMainActivity();
                break;
            case R.id.rl_worker:
                SharedPrefUtils.saveInt(this, "GENERATION", WORKER);
                startMainActivity();
                break;
            case R.id.iv_id_back:
                cvSex.setVisibility(View.VISIBLE);
                cvId.setVisibility(View.GONE);
                break;
            default:

            break;
        }
    }

    //开启主界面，并把第一次选择置为true存储进SharedPrefUtils
    private void startMainActivity() {
        SharedPrefUtils.saveBoolean(this,"ISFIRSTCHOOSE",ISFIRSTCHOOSE);
        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);
        finish();
    }
}
